package com.pur.zsms.documentsmanage.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Query;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.pur.zsms.common.dao.GenericDao;
import com.pur.zsms.common.dao.JpaTemplate;
import com.pur.zsms.common.exception.GenericException;
import com.pur.zsms.common.support.PageController;
import com.pur.zsms.common.support.PaginationSupport;
import com.pur.zsms.documentsmanage.dao.IDomDao;
import com.pur.zsms.documentsmanage.po.DomPo;
import com.pur.zsms.foodmanage.food.dao.IFoodDao;
import com.pur.zsms.foodmanage.food.po.FoodMaterPo;
import com.pur.zsms.foodmanage.food.po.FoodPo;
import com.pur.zsms.foodmanage.food.vo.FoodMaterVo;
import com.pur.zsms.foodmanage.food.vo.FoodVo;
import com.pur.zsms.pmsnmanage.menu.po.MenuPo;
import com.pur.zsms.pmsnmanage.role.vo.RoleVo;
import com.pur.zsms.pmsnmanage.user.dao.IUserDao;
import com.pur.zsms.pmsnmanage.user.po.UserPo;
import com.pur.zsms.pmsnmanage.user.po.UserRolePo;
import com.pur.zsms.pmsnmanage.user.vo.UserVo;
import com.pur.zsms.systemsetting.datadictionary.po.CodeType;

@Repository("domDao")
public class DomDaoImpl extends GenericDao implements IDomDao {

	public List<DomPo> getDomPoListByParentId(int domId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from DomPo o where o.parentDomId='" + domId + "'");
		List<DomPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List<DomPo> getLinkById(int domId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from DomPo o where o.domId='" + domId + "'");
		List<DomPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List<DomPo> getDomPoByText(String text) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from DomPo o where o.domText='" + text + "'");
		List<DomPo> list = template.find(ql.toString(), null);
		return list;
	}

	public List<DomPo> getDomPoByDomId(int domId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" select o ");
		ql.append(" from DomPo o where o.domId='" + domId + "'");
		List<DomPo> list = template.find(ql.toString(), null);
		return list;
	}

	public void addDomPo(DomPo domPo) throws GenericException {
		this.persist(domPo);
	}

	public void deleteDomPo(int domId) throws GenericException {
		JpaTemplate template = this.getTemplate();
		StringBuffer ql = new StringBuffer();
		ql.append(" delete DomPo o where o.domId=" + domId);
		template.executeUpdate(ql.toString());
	}

}
